;;; A state that synchronizes with the fmri scanner's pulse.

(in-package :experiment)

(defclass synchronize-pulse (state)
  ((n :initform 1 :initarg :n :accessor synchronize-pulse-n)))

(defclass dummy-synchronize-pulse (state)
  ())

(defmethod state-init (exp (state dummy-synchronize-pulse))
  (lg 'start)
  (state-onward exp state))

(defmethod state-init (exp (state synchronize-pulse))
  (exp:log exp 'start)
  ;; do nothing
  )

(define-action count-pulses ((state synchronize-pulse)
                             (keypress :char #\^))
  (decf (synchronize-pulse-n state))
  (exp:lg 'pulse)
  (when (<= (synchronize-pulse-n state) 0)
    (state-onward *experiment* state)))

(defmethod exp:state-list-actions append (experiment (state synchronize-pulse))
  (default-list-event-translations state))
